<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="common/header.jsp" %>
<div class="clearfix"></div>
<div class="row">
    <div class="col-md-12 col-sm-12 col-xs-12">
        <div class="x_panel">
            <div class="x_title">
                <h2>修改APP基础信息 <i class="fa fa-user"></i><small></small></h2>
                <div class="clearfix"></div>
            </div>
            <div class="x_content">
                <form class="form-horizontal form-label-left"
                      action="${pageContext.request.contextPath}/eve/updataInfomodifys" method="post"
                      enctype="multipart/form-data">
                    <input type="hidden" name="modifyBy" id="modifyBy" value="${user.id}">
                    <input type="hidden" name="id" id="id" value="${mapInfo.id}">
                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">软件名称 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input id="softwareName" class="form-control col-md-7 col-xs-12"
                                   data-validate-length-range="20" data-validate-words="1"
                                   name="softwareName" value="${mapInfo.softwareName}" required="required"
                                   placeholder="请输入软件名称" type="text">
                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">APK名称 <span
                                class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input id="APKName" type="text" class="form-control col-md-7 col-xs-12"
                                   name="APKName" value="${mapInfo.APKName}" readonly="readonly">
                        </div>
                    </div>

                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">支持ROM <span
                                class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input id="supportROM" class="form-control col-md-7 col-xs-12"
                                   name="supportROM" value="${mapInfo.supportROM}" required="required"
                                   data-validate-length-range="20" data-validate-words="1"
                                   placeholder="请输入支持的ROM" type="text">
                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">界面语言 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input id="interfaceLanguage" class="form-control col-md-7 col-xs-12"
                                   data-validate-length-range="20" data-validate-words="1" required="required"
                                   name="interfaceLanguage" value="${mapInfo.interfaceLanguage}"
                                   placeholder="请输入软件支持的界面语言" type="text">
                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="number">软件大小 <span
                                class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="number" id="softwareSize" name="softwareSize" value="${mapInfo.softwareSize}"
                                   required="required"
                                   data-validate-minmax="10,500" placeholder="请输入软件大小，单位为Mb"
                                   class="form-control col-md-7 col-xs-12">
                        </div>
                    </div>

                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="number">下载次数 <span
                                class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="number" id="downloads" name="downloads" value="${mapInfo.downloads}"
                                   required="required"
                                   data-validate-minmax="10,500" placeholder="请输入下载次数"
                                   class="form-control col-md-7 col-xs-12">
                        </div>
                    </div>

                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="select">所属平台 <span
                                class="required">*</span></label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="hidden" value="${mapInfo.status}" id="fid"/>
                            <select name="flatFormId" id="flatformId" class="form-control" required="required"></select>
                        </div>
                    </div>

                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="select">一级分类 <span
                                class="required">*</span></label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="hidden" value="${mapInfo.categoryLevel1}" id="cl1"/>
                            <select name="categoryLevel1" id="categoryLevel1" class="form-control"
                                    required="required"> </select>
                        </div>
                    </div>

                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="select">二级分类 <span
                                class="required">*</span></label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="hidden" value="${mapInfo.categoryLevel2}" id="cl2"/>
                            <select name="categoryLevel2" id="categoryLevel2" class="form-control"
                                    required="required"></select>
                        </div>
                    </div>

                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="select">三级分类 <span
                                class="required">*</span></label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="hidden" value="${mapInfo.categoryLevel3}" id="cl3"/>
                            <select name="categoryLevel3" id="categoryLevel3" class="form-control"
                                    required="required"></select>
                        </div>
                    </div>

                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">APP状态 <span
                                class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input id="statusName" type="text" class="form-control col-md-7 col-xs-12"
                                   name="statusName" value="${mapInfo.statusName}" readonly="readonly">
                            <input type="hidden" name="status" id="status" value="${mapInfo.status}">

                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="textarea">应用简介 <span
                                class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <textarea id="appInfo" name="appInfo" required="required"
                                      placeholder="请输入本软件的相关信息，本信息作为软件的详细信息进行软件的介绍。"
                                      class="form-control col-md-7 col-xs-12"> ${mapInfo.appInfo}
                            </textarea>
                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">LOGO图片 <span
                                class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="hidden" id="logoPicPath" name="logoPicPath" value="${mapInfo.logoPicPath}"/>
                            <input type="hidden" id="logoLocPath" name="logoLocPath" value="${mapInfo.logoLocPath}"/>
                            <div id="uploadfile" style="display: none">
                                <input id="attach" type="file" class="form-control col-md-7 col-xs-12" name="attach">
                                <p><span
                                        style="color:#ff0000;font-weight: bold;">*注：1、大小不得超过500k.2、图片格式：jpg、png、jpeg、pneg</span>
                                </p>
                            </div>
                            <div id="logoFile"></div>
                            ${fileUploadError }
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-6 col-md-offset-3">

                            <button id="send" type="submit" name="status" value="1" class="btn btn-success">
                                保存并再次提交审核
                            </button>

                            <button id="send" type="submit" class="btn btn-success">保存</button>
                            <button type="button" class="btn btn-primary" id="back">返回</button>
                            <br/><br/>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<%@include file="common/footer.jsp" %>
<%--<script src="${pageContext.request.contextPath }/statics/localjs/appinfomodify.js"></script>--%>

<script>
    $(function () {

        var att = $("#attach").val();

        console.log("---------->>>>>", att)

        $("#attach").change(function () {
            var files = $("#attach").val();

            var sum = files.lastIndexOf(".");

            files.substring(0, sum);

            var print = files.substring(sum + 1);//截取文件后缀

            var reg = /(?:jpg|gif|png|jpeg)$/;

            if (reg.test(print)) {

                console.log("文件名为：", print);
            } else {
                alert("抱歉您上传的不是一张图片！请重新上传！")
                $("#attach").val('');
            }
        })
    })
</script>

<script src="${pageContext.request.contextPath}/statics/localjs/appinfoview.js"></script>

<script>

    function loadCategoryLevel(pid, cl, categoryLevel) {
        //动态加载一级分类列表
        $.ajax({
            type: "GET",//请求类型
            url: "/eve/categorylevellist.json",//请求的url
            data: {pid: pid},//请求参数
            dataType: "json",//ajax接口（请求url）返回的数据类型
            success: function (data) {//data：返回数据（json对象）
                $("#" + categoryLevel).html("");

                var options = "<option value=\"\">--请选择--</option>";
                for (var i = 0; i < data.length; i++) {
                    if (cl != null && cl != undefined && data[i].id == cl) {
                        options += "<option selected='selected' value=" + data[i].id + " >" + data[i].categoryName + "</option>";
                    } else {
                        options += "<option value=" + data[i].id + ">" + data[i].categoryName + "</option>";
                    }
                }
                $("#" + categoryLevel).html(options);
            },
            error: function (data) {//当访问时候，404，500 等非200的错误状态码
                alert("加载", cl, "级分类列表失败！");
            }
        });
    }

    $(function () {
        //动态加载所属平台列表
        $.ajax({
            type: "GET",//请求类型
            url: "/eve/datadictionarylist.json",//请求的url
            data: {tcode: "APP_FLATFORM"},//请求参数
            dataType: "json",//ajax接口（请求url）返回的数据类型
            success: function (data) {//data：返回数据（json对象）
                var fid = $("#fid").val();
                $("#flatformId").html("");
                var options = "<option value=\"\">--请选择--</option>";
                for (var i = 0; i < data.length; i++) {

                    if (fid != null && fid != undefined && data[i].valueId == fid) {

                        options += "<option selected='selected'  value=" + data[i].valueId + ">" + data[i].valueName + "</option>"
                    } else {
                        options += "<option  value=" + data[i].valueId + ">" + data[i].valueName + "</option>"
                    }
                }
                $("#flatformId").html(options);
            },
            error: function (data) {//当访问时候，404，500 等非200的错误状态码
                alert("加载平台列表失败！");
            }
        });

        var cl1 = $("#cl1").val();
        var cl2 = $("#cl2").val();
        var cl3 = $("#cl3").val();

        console.log("1------------->", cl1, "------2-------->>", cl2, "----------3----------->", cl3);

        //动态加载一级分类列表
        loadCategoryLevel(0, cl1, "categoryLevel1");
        //动态加载二级分类列表
        loadCategoryLevel(cl1, cl2, "categoryLevel2");
        //动态加载三级分类列表
        loadCategoryLevel(cl2, cl3, "categoryLevel3");

        //联动效果：动态加载二级分类列表
        $("#categoryLevel1").change(function () {
            var categoryLevel1 = $("#categoryLevel1").val();
            if (categoryLevel1 != '' && categoryLevel1 != null) {
                loadCategoryLevel(categoryLevel1, cl2, "categoryLevel2");
            } else {
                $("#categoryLevel2").html("");
                var options = "<option value=\"\">--请选择--</option>";
                $("#categoryLevel2").html(options);
            }
            $("#categoryLevel3").html("");
            var options = "<option value=\"\">--请选择--</option>";
            $("#categoryLevel3").html(options);
        });

        //联动效果：动态加载三级分类列表
        $("#categoryLevel2").change(function () {
            var categoryLevel2 = $("#categoryLevel2").val();
            if (categoryLevel2 != '' && categoryLevel2 != null) {
                loadCategoryLevel(categoryLevel2, cl3, "categoryLevel3");
            } else {
                $("#categoryLevel3").html("");
                var options = "<option value=\"\">--请选择--</option>";
                $("#categoryLevel3").html(options);
            }
        });
    });
</script>

<script>
    function delfile(id) {

        $.ajax({
            type: "post",//请求类型
            url: "/eve/delfileByInfo",//请求的url
            data: {id: id},//请求参数
            dataType: "json",//ajax接口（请求url）返回的数据类型
            success: function (data) {//data：返回数据（json对象）
                if (data.result == "success") {
                    alert("删除成功！");
                    $("#uploadfile").show();
                    $("#logoFile").html('');
                } else if (data.result == "failed") {
                    alert("删除失败！");
                }
            },
            error: function (data) {//当访问时候，404，500 等非200的错误状态码
                alert("请求错误！");
            }
        });
    }

    $(function () {
        //上传APK文件---------------------
        var logoPicPath = $("#logoPicPath").val();
        var id = $("#id").val();
        var apkFileName = $("#apkFileName").val();
        if (logoPicPath == null || logoPicPath == "") {
            $("#uploadfile").show();
        } else {
            $("#logoFile").append("<p><img src=\"" + logoPicPath + "?m=" + Math.random() + "\" width=\"100px;\"/> &nbsp;&nbsp;" +
                "<a href=\"javascript:;\" onclick=\"delfile('" + id + "');\">删除</a></p>");
        }
    });

</script>
